package com.googlecode.continuity.plugin.project.server.service;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.googlecode.continuity.plugin.project.client.Project;
import com.googlecode.continuity.plugin.project.client.Milestone;

/**
 * ProjectServiceHibernate
 *
 * @author Peter Schmitt <aragos@aragos.de>
 */
public class ProjectServiceHibernate extends HibernateDaoSupport implements ProjectService {
  public Project getProjectByID(int id) {
    return (Project) getHibernateTemplate().find("from Project where id=?", id).get(0);
  }

  public List<Project> getAvailableProjects() {
    return getHibernateTemplate().find("from Project");
  }

  public void storeProject(Project project) {
    getHibernateTemplate().saveOrUpdate(project);
  }

  public Milestone getMilestoneByID(int id) {
    return (Milestone) getHibernateTemplate().find("from Milestone where id=?", id).get(0);
  }

  public void storeMilestone(Milestone milestone) {
    getHibernateTemplate().saveOrUpdate(milestone); 
  }

  public List<Milestone> findMilestones(String search) {
    return getHibernateTemplate().find("from Milestone where name like ?", "%" + search + "%");
  }
}
